package logic

import (
	"cart_srv/model/redis"
	"context"
	"fmt"

	"cart_srv/cart"
	"cart_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartDelLogic {
	return &CartDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CartDelLogic) CartDel(in *cart.CartDelRequest) (*cart.CartDelResponse, error) {
	// todo: add your logic here and delete this line
	err := redis.StockDel(in.UserId, in.GoodId)
	if err != nil {
		return nil, fmt.Errorf("删除失败")
	}
	return &cart.CartDelResponse{Success: true}, nil
}
